import { createStore } from 'vuex'
import {articles,bulletin} from "../../services/api"

export default {
    state: () => ({
        mumalList:[],
        noticesList:[],
        zixun:[]
    }),
    mutations: {
      setmumalList(state,data){
            state.mumalList = [...state.mumalList,...data]
      },
      setnoticesList(state,data){
        state.noticesList = [...state.noticesList,...data]
      },
      setzixun(state,data){
        state.noticesList = [...state.noticesList,...data]
      }
    },
    actions: {
      article({commit},data){
          return new Promise((resolve,reject)=>{
            articles(data).then(res=>{
              if(res.code==0){
                  commit('setmumalList',res.data.list)
                  resolve(res.data.list)
              }
            })
          })
      },
      notices({commit},data){
        return new Promise((resolve,reject)=>{
          bulletin().then(res=>{
            if(res.code==0){
                commit('setnoticesList',res.data)
                resolve(res.data)
            }
          })
        })
      },    
      zixuns({commit},data){
        return new Promise((resolve,reject)=>{
          articles(data).then(res=>{
            if(res.code==0){
                commit('setzixun',res.data.list)
                resolve(res.data.list)
            }
          })
        })
      },   
    },

  }